const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    type: 282,
    input_config:[],
    price_config: [],
    result:[],
    selectIndex:0,
    items:[],
    config_load :false,
    searched:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
    if (options.type) {
      this.setData({
        type: options.type
      })
    }
   
    this.getConfig()
  },

  getConfig() {

    wx.showLoading({
      title: '加载中',
    })

    let that = this

    app.http.post('/car_platform/public/index.php/api/getFunctionConfig', {
      data: { type: this.data.type},
      type: this.data.type,
      baseUrl: 'https://www.cheapercheaper.top'
    })
    .then(res => {
        console.log(res)
        if (res.success) {
          that.setData({
            input_config: res.obj.param_config,
            price_config: res.obj.price_config,
            items:res.obj.mock_config
          })
        }
        that.setData({
          config_load:true
        })
        wx.showToast({
          title: res.msg,
          icon: 'none'
        })
      }).catch(res => {
        console.log(res)
        wx.hideLoading()
      })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  bindPickerChange(e) {
    let index = e.target.dataset.index
 
    this.setData({
      selectIndex: e.detail.value
    })
  },
  isArray(item) { 
    console.log(item) 
  return item instanceof Array 
  },
  formSubmit(e){
    console.log('form发生了submit事件，携带数据为：', e.detail.value)

    wx.showLoading({
      title: '加载中',
    })

    let that = this

    let data = e.detail.value
    data.type = this.data.type

    app.http.post('/car_platform/public/index.php/api/queryCommon', {
      data: data,
      baseUrl: 'https://www.cheapercheaper.top'
    })
      .then(res => {
        console.log(res)
        if (res.success) {
         
          that.setData({
            items: res.obj,
            searched:true
          })
        }
        that.setData({
          config_load: true
        })
        wx.showToast({
          title: res.msg,
          icon: 'none'
        })
      }).catch(res => {
        console.log(res)
        wx.hideLoading()
      })
  }
})